package com.android.filepickerdemo;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.blankj.utilcode.util.ResourceUtils;
import com.blankj.utilcode.util.SDCardUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.tiger.filepicker.ExplorerConfig;
import com.tiger.filepicker.FileExplorer;
import com.tiger.filepicker.annotation.ExplorerMode;
import com.tiger.filepicker.contract.OnFileClickedListener;

import java.io.File;

public class MainActivity extends AppCompatActivity implements OnFileClickedListener {

    private ExplorerConfig explorerConfig;

    private FileExplorer fileExplorer;
    private Button okBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        fileExplorer = findViewById(R.id.idFileExplorer);
        fileExplorer.load(getExplorerConfig());

        okBtn= findViewById(R.id.idButton);
        okBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
    }


    public ExplorerConfig getExplorerConfig() {
        if(explorerConfig == null){
            explorerConfig = new ExplorerConfig(this.getApplication());
        }
        explorerConfig.setRootDir(new File(SDCardUtils.getSDCardPathByEnvironment()));
        explorerConfig.setLoadAsync(true);
        explorerConfig.setExplorerMode(ExplorerMode.FILE);
        explorerConfig.setShowHomeDir(false);
        explorerConfig.setShowUpDir(true);
        explorerConfig.setShowHideDir(true);
        explorerConfig.setFolderIcon(ResourceUtils.getDrawable(R.mipmap.ic_folder));
        explorerConfig.setFileIcon(ResourceUtils.getDrawable(R.mipmap.ic_file));
        explorerConfig.setOnFileClickedListener(this);
        String[] extension = new String[]{".txt",".dxf",".csd"};
        explorerConfig.setAllowExtensions(extension);
        return explorerConfig;
    }

    @Override
    public void onFileClicked(@NonNull File file) {
        ToastUtils.showShort(file.getAbsolutePath());
    }
}